package com.wao.menu.service.mapper;

import com.wao.menu.domain.*;
import com.wao.menu.service.dto.ItemDTO;

import org.mapstruct.*;

/**
 * Mapper for the entity Item and its DTO ItemDTO.
 */
@Mapper(componentModel = "spring", uses = {MenuMapper.class, })
public interface ItemMapper extends EntityMapper <ItemDTO, Item> {

    @Mapping(source = "menu.id", target = "menuId")
    @Mapping(source = "menu.name", target = "menuName")

    @Mapping(source = "parent.id", target = "parentId")
    @Mapping(source = "parent.name", target = "parentName")
    ItemDTO toDto(Item item); 
    @Mapping(target = "children", ignore = true)

    @Mapping(source = "menuId", target = "menu")

    @Mapping(source = "parentId", target = "parent")
    Item toEntity(ItemDTO itemDTO); 
    default Item fromId(Long id) {
        if (id == null) {
            return null;
        }
        Item item = new Item();
        item.setId(id);
        return item;
    }
}
